package com.common.basic.base;

import java.io.Serializable;
import java.util.Collection;

public class BaseCommand implements Serializable {

	private static final long serialVersionUID = -5528844928997752101L;

	private int pgIndex = 1;
	
	private int pgRows  = 10;
	
	private int pgTotal;	
	
	private Collection<?> data;

	private String strAction;

	private String[] selectedRecord;
	
	private String strSortingDT;
	/**
	 * 
	 */
	public BaseCommand(){}
	
	/**
	 * @param index
	 */
	public BaseCommand(int pgIndex){
		this.pgIndex = pgIndex;
	}
	
	/**
	 * @param index
	 * @param rowsPerPage
	 */
	public BaseCommand(int pgIndex, int pgRows){
		this(pgIndex);
		this.pgRows = pgRows;
	}
	
	/**
	 * @param pgIndex
	 * @param pgRows
	 * @param total
	 */
	public BaseCommand(int pgIndex, int pgRows, int pgTotal){
		this(pgIndex, pgRows);
		this.pgTotal = pgTotal;
	}
	
	/**
	 * @param pgIndex
	 * @param pgRows
	 * @param pgTotal
	 * @param data
	 */
	public BaseCommand(int pgIndex, int pgRows, int pgTotal, Collection<?> data){
		this(pgIndex, pgRows, pgTotal);
		this.data = data;
	}
	

	/**
	 * @return the pgIndex
	 */
	public int getPgIndex() {
		return pgIndex;
	}

	/**
	 * @param pgIndex the pgIndex to set
	 */
	public void setPgIndex(int pgIndex) {
		this.pgIndex = pgIndex;
	}

	/**
	 * @return the pgRows
	 */
	public int getPgRows() {
		return pgRows;
	}

	/**
	 * @param pgRows the pgRows to set
	 */
	public void setPgRows(int pgRows) {
		this.pgRows = pgRows;
	}

	/**
	 * @return the pgTotal
	 */
	public int getPgTotal() {
		return pgTotal;
	}

	/**
	 * @param pgTotal the pgTotal to set
	 */
	public void setPgTotal(int pgTotal) {
		this.pgTotal = pgTotal;
	}

	/**
	 * @return the data
	 */
	public Collection<?> getData() {
		return data;
	}

	/**
	 * @param data the data to set
	 */
	public void setData(Collection<?> data) {
		this.data = data;
	}

	/**
	 * @param pgTotalRecords
	 */
	public void calculate(int pgTotalRecords)
	{
		if(getPgRows()<=0)
			setPgRows(10);
		int pgIdx    = getPgIndex();	        
		int pgRows   = getPgRows();
		int pgTotal  = 0;
		int pgRowGrp = pgTotalRecords / pgRows;
		int pgRowMod = pgTotalRecords % pgRows;        
        if (pgRowMod == 0)
            pgTotal = pgRowGrp;
        else
            pgTotal = pgRowGrp + 1;        
        if (pgTotal == 0) pgTotal = 1;
        if (pgIdx <= 0) pgIdx = 1;
        if (pgIdx > pgTotal) pgIdx = pgTotal;        
        setPgIndex(pgIdx);
        setPgRows(pgRows);
        setPgTotal(pgTotal);
	}

	public void setSelectedRecord(String[] selectedRecord) {
		this.selectedRecord = selectedRecord;
	}

	public String[] getSelectedRecord() {
		return selectedRecord;
	}

	public void setStrAction(String strAction) {
		this.strAction = strAction;
	}

	public String getStrAction() {
		return strAction;
	}

	public void setStrSortingDT(String strSortingDT) {
		this.strSortingDT = strSortingDT;
	}

	public String getStrSortingDT() {
		return strSortingDT;
	}
}
